﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using KpBusiness.Model;
using KpBusiness.Service;
using KpMis.Utility;
using KpMis.ViewModel;
namespace KpMis.Controllers
{ 
    public class RoleController : Controller
    {
        
        //
        // GET: /Role/

        public ViewResult Index()
        {
            ViewBag.groupTypeList = GroupTypeList.GroupList;
            return View(new RoleService().GetAllRoles());
        }

        //
        // GET: /Role/Details/5

        public ViewResult Details(int id)
        {
            Role role = new RoleService().GetRole(id);
            return View(role);
        }

        //
        // GET: /Role/Create

        public ActionResult Create()
        {
            
            return View();
        } 

        //
        // POST: /Role/Create

        [HttpPost]
        public ActionResult Create(Role role)
        {
            if (ModelState.IsValid)
            {
                role.LastUpdatedDate = DateTime.Now;
                role.LastUpdatedUser = CurrentUser.GetCurrentUserName();
                new RoleService().SaveRole(role);
                return RedirectToAction("Index");  
            }

            return View(role);
        }
        
        //
        // GET: /Role/Edit/5
 
        public ActionResult Edit(int id)
        {
            Role role = new RoleService().GetRole(id);
            
            //ViewBag.selectedType = (int) role.GroupType;
            return View(role);
        }

        //
        // POST: /Role/Edit/5

        [HttpPost]
        public ActionResult Edit(Role role)
        {
            if (ModelState.IsValid)
            {
                role.LastUpdatedDate = DateTime.Now;
                role.LastUpdatedUser = CurrentUser.GetCurrentUserName();
                new RoleService().SaveRole(role);
                return RedirectToAction("Index");
            }
            return View(role);
        }

        //
        // GET: /Role/Delete/5
 
        public ActionResult Delete(int id)
        {
            Role role = null;
            return View(role);
        }

        //
        // POST: /Role/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(int id)
        {            
            
            return RedirectToAction("Index");
        }

        protected override void Dispose(bool disposing)
        {
       
            base.Dispose(disposing);
        }
    }
}